{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "# Define the directory path\n",
    "# path = \"/share/saves/qwen2_vl_7b\"\n",
    "path = \"/share/saves/qwen2_vl_7b/lora-infer\"\n",
    "\n",
    "# Function to list all files in a directory including subdirectories\n",
    "def list_files(directory, file_name='generated_predictions.jsonl', dataset='mire_test', param='bs16'):\n",
    "    files_list = []\n",
    "    for root, dirs, files in os.walk(directory):\n",
    "        for file in files:\n",
    "            files_list.append(os.path.join(root, file))\n",
    "    files_list = [file for file in files_list if file.endswith(file_name) and dataset in file and param in file ]\n",
    "    # files_list = [file for file in files_list if file.endswith(file_name)]\n",
    "    return files_list\n",
    "\n",
    "# List all files in the specified directory\n",
    "all_files = list_files(path)\n",
    "all_files\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "len(all_files)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from convert2submit import convert2submit\n",
    "date='1120'\n",
    "import os\n",
    "os.makedirs(f'./submit-{date}', exist_ok=True)\n",
    "test_file = \"/home/lyc/TNTprojectz/LLaMA-Factory/data/mire/test1/test1.json\"\n",
    "for prediction_file in all_files:\n",
    "    # save_path = \"submit.csv\"\n",
    "    save_path = prediction_file.replace(\"generated_predictions.jsonl\", \"submit.csv\").replace('/share/saves/', '').replace('/', '-')\n",
    "    save_path = f'./submit-{date}/{save_path}'\n",
    "    print(save_path)\n",
    "    convert2submit(test_file, prediction_file, save_path)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from convert2submit import convert2submit\n",
    "date='1125'\n",
    "import os\n",
    "os.makedirs(f'./submit-{date}', exist_ok=True)\n",
    "\n",
    "test_file = \"/root/LLaMA-Factory/data/mire/test1/test1.json\"\n",
    "prediction_file_list = [\n",
    "    \"/root/autodl-fs/generated_predictions.jsonl\",\n",
    "]\n",
    "\n",
    "for prediction_file in prediction_file_list:\n",
    "    # save_path = \"submit.csv\"\n",
    "    save_path = prediction_file.replace(\"generated_predictions.jsonl\", \"submit.csv\").replace('/root/autodl-fs/', '').replace('/', '-')\n",
    "    save_path = f'./submit-{date}/{save_path}'\n",
    "    print(save_path)\n",
    "    convert2submit(test_file, prediction_file, save_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "! pip install pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
